package com.it2297.renderer;

import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import com.it2297.model.Product;

public class DeleteProductCellRenderer extends JLabel implements
		TableCellRenderer {

	private Product product;
	private JCheckBox cb;

	public DeleteProductCellRenderer() {
		setOpaque(true);
		setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
		setVerticalTextPosition(JLabel.TOP);
		setIconTextGap(10);
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object object,
			boolean isSelected, boolean hasFocus, int row, int column) {
		product = (Product) object;

		switch (column) {
		case 0:
			Image bg = Toolkit
					.getDefaultToolkit()
					.createImage(
							System.getProperty("user.dir")
									+ "/img/product-img/"
									+ product.getProdName() + ".png")
					.getScaledInstance(100, 70, Image.SCALE_DEFAULT);
			setIcon(new ImageIcon(bg));
			setText("<html><strong> Product-name: " + product.getProdName()
					+ "</strong><br/>Description: " + product.getDesc()
					+ "<br/>Category: " + product.getCategory() + "<html>");
			break;
		case 1:
			setIcon(null);
			setText("<html><strong> Price: </strong><br/>" + product.getPrice()
					+ "<br> <input type='checkbox' name='productCheck' values="
					+ product.getProdName() + " >check to delete</html>");
			break;
		}

		if (row % 2 == 0) {
			setBackground(Color.WHITE);
		} else {
			setBackground(new Color(240, 240, 240));
		}

		setForeground(Color.BLACK);
		return this;
	}
}
